import request from '@/utils/request';
import { UserForm, UserInfo, UserPageVO, UserQuery, ChangePwd } from './types';

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export  function getUserInfo(): UserInfo {
  return request({
    url: '/api/account/my-profile',
    method: 'get'
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
  queryParams: UserQuery
): PageResult<UserPageVO[]> {
  return request({
    url: '/api/v1/users/page',
    method: 'get',
    params: queryParams
  });
}


/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: '/api/identity/users',
    method: 'post',
    data: data
})
}


//添加用户 并添加用户组织的接口
export function addUserToOrganization(data:any) {
  return request({
      url: '/api/identity/users/create-to-organization',
      method: 'post',
      data: data
  })
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUserProfile(data: UserForm) {
  return request({
    url: '/api/account/my-profile',
    method: 'put',
    data: data
  });
}



/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(data: ChangePwd) {
  return request({
    url: '/api/account/my-profile/change-password',
    method: 'post',
    data: data
  });
}


/*
* 获取用户列表
*/
export function getUserlist(data: any) {
  return request({
    url: '/api/identity/users',
    method: 'get',
    params: data
  });
}

/**
 * 删除用户
 *
 * @param id
 */
export function deleteUser(id: string) {
  return request({
    url: `/api/identity/users/deleteuser/${id}`,
    method: 'delete'
  });
}


/**
 * 修改用户
 * @param id 
 * @param data 
 * @returns 
 */
export function updateUserToOrg(id:string, data:any) {
  return request({
      url: `/api/identity/users/${id}/update-to-organizations`,
      method: 'put',
      data: data
  })
}
//根据用户id获取用户信息
export function getUserinfoById(id:string) {
  return request({
      url: `/api/identity/users/${id}`,
      method: 'get',
  })
}

//根据用户id获取组织信息
export function getOrganizationByUserId(id:string) {
  return request({
      url: `/api/identity/users/${id}/organizations`,
      method: 'get',
      params: {
          includeDetails: false
      }
  })
}

//根据用户id获取角色信息
export function getRolesbyUserId(id:string) {
  return request({
      url: `/api/identity/users/${id}/roles`,
      method: 'get',
  })
}

export function getUsersInoOrganizationunit(param:any) {
  return request({
      url: '/api/identity/users/user-in-organization',
      method: 'get',
      params: param
  })
}

export function getOrgUnbindUser(param:any){
  return request({
    url:'/api/identity/organizationUnit/org-unbind-user',
    method:'get',
    params:param
  });
}

export function adddUserToOrg(data:any){
   return request({
    url:'/api/identity/users/add-user-to-organization',
    method:'post',
    data:data
   })
} 

export function removeUserFromOrg(param:any){
  return request({
    url:'/api/identity/users/remove-user-from-organization',
    method:'delete',
    params:param
   })
}


//获取所有的用户
export function getalluserlist() {
  return request({
      url: `/api/identity/users/all`,
      method: 'get'
  })
}